from scrapy.contrib.downloadermiddleware.useragent import UserAgentMiddleware
from fake_useragent import UserAgent

class MyUAConfig(UserAgentMiddleware):
    def __init__(self):
        self.user_agent = user_agent

    def process_request(self, request, spider):
        ua = UserAgent().random
        while ua.find("Windows") == -1:
            ua = UserAgent().random
        print(ua)
        request.headers.setdefault('User-Agent', ua)